import { View, Image } from '@tarojs/components';
import Taro from '@tarojs/taro';
import React, { Component } from 'react';
import { connect } from 'react-redux';
import './index.less';
import * as T from './types';
import actions from './actions';
import { store2Props } from './selectors';
import Top from './components/top/index';
import Menu from './components/menu/index';
import List from './components/list/index';
import {IPLAND_OSS_HOST} from '../../constant';

//@ts-ignore
actions().actions.loadReducer();
@connect<Partial<T.IProps>, any>(store2Props, actions)
export default class packageIShop extends Component<Partial<T.IProps>, any> {
  constructor(props) {
    super(props);
    this.state = {
    };
  }
  componentDidShow() {
    this.props.actions.init();
  }

  componentWillMount() {
    if (__TARO_ENV !== 'h5') {
      Taro.showShareMenu({
        withShareTicket: true,
      });
    }
  }
  onShareAppMessage() {
    let wechatShareInfo = JSON.parse(Taro.getStorageSync('wechatShareInfo'));
    return {
      title: wechatShareInfo.title,
      imageUrl: wechatShareInfo.imgUrl[0].url,
    };
  }
  onShareTimeline() {
    // 默认分享内容
  }

  componentWillUnmount() {
    this.props.actions.clean();
  }

  render() {
    let {
      main: { },
      actions: { action }
    } = this.props;
    return (
      <View className="packageIShop">
        <Top />
        <Menu />
        <List />
        <Image className="cart" src={`${IPLAND_OSS_HOST}shop/cart.png`} mode="widthFix" />
      </View>
    )
  }
}

//create by moon https://github.com/creasy2010/moon
